package com.zed.games.core;

import com.zed.api.games.Action;
import com.zed.api.games.GameBuilder;
import com.zed.api.games.GameLevel;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * 缺省的游戏仓储
 *
 * @author Zed
 */
public abstract class AbstractGameBuilder<S, A extends Action> implements GameBuilder<S, A> {

    private String name;
    private List<GameLevel<S, A>> levels;

    @Override
    public GameBuilder<S, A> name(String name) {
        this.name = name;
        return this;
    }

    @Override
    public GameBuilder<S, A> addGameLevel(GameLevel<S, A> gameLevel) {
        if (this.levels == null) {
            this.levels = new ArrayList<>();
        }
        this.levels.add(gameLevel);
        return this;
    }

    @Override
    public GameBuilder<S, A> removeGameLevel(GameLevel<S, A> gameLevel) {
        if (this.levels != null) {
            this.levels.remove(gameLevel);
        }
        return this;
    }

    @Override
    public String getName() {
        return this.name;
    }

    @Override
    public List<GameLevel<S, A>> getGameLevels() {
        return Collections.unmodifiableList(this.levels);
    }

}
